<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        判断一个数是质数还是合数
     -->
</head>

<body>

</body>
<script>
    let num = parseInt(prompt('请输入一个数(大于1的自然数):'));
    isPrimeNumber(num);

    function isPrimeNumber(num) {
        if (num <= 1) {
            alert('输入的既不是质数也不是合数，请重新输入！');
            num = parseInt(prompt('请输入一个数(大于1的自然数):'));
            isPrimeNumber(num);
        } else {
            let flag = true;
            for (let i = 2; i < num; i++) {
                if (num % i == 0) {
                    flag = false;
                }
            }
            if (flag) {
                alert(num + "是质数");
            } else {
                alert(num + "是合数");
            }
        }
    }
</script>

</html>